using System;
using THANHTUNGO.Portal.Components.UI;
using THANHTUNGO.Portal.Modules.DOWNLOAD.Components;

namespace THANHTUNGO.Portal.Modules.DOWNLOAD.Controls
{
    public partial class CategoryManager : YAFAddEditPage
    {
        protected void btnAddCategory_Click(object sender, EventArgs e)
        {
            Category category = new Category();
            category.ParentID = 0;
            category.Name = txtCategoryName.Text;
            category.ModuleID = this.ModuleID;
            category.Insert();
            
            gvCategories.DataBind();
            txtCategoryName.Text = string.Empty;
        }

        protected void btnAddSubCategory_Click(object sender, EventArgs e)
        {
            Category category = new Category();
            category.ParentID = Convert.ToInt32(gvCategories.SelectedValue);
            category.Name = txtSubCategoryName.Text;
            category.ModuleID = this.ModuleID;
            category.Insert();

            gvSubCategories.DataBind();
            txtSubCategoryName.Text = string.Empty;
        }

        protected void gvCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            tblAddSubCategory.Visible = gvCategories.SelectedIndex >= 0;
        }

        protected void hfModuleID_Init(object sender, EventArgs e)
        {
            hfModuleID.Value = this.ModuleID.ToString();
        }
    }
}